package com.nuc.bigdata.controller;

import com.nuc.bigdata.orm.dto.ShopCarGoodsDto;
import com.nuc.bigdata.orm.feign.ShopCarFeign;
import com.nuc.bigdata.service.ShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackLuo
 * @date 2019/12/5
 */
@RestController
@RequestMapping("/oa-shopping-cart")
public class ShopCarController {

    private final ShopCarService carService;

    @Autowired
    ShopCarController(ShopCarService carService) {
        this.carService = carService;
    }

    @GetMapping("/car/{userId}")
    public ShopCarFeign queryByUserId(@PathVariable("userId")String userId) {
        return carService.queryCarFeignByUserId(userId);
    }

    @PostMapping("/car/{userId}/goods")
    public void addGoodsIntoCar(@RequestBody ShopCarGoodsDto goodsDto,
                                @PathVariable("userId")String userId) {
        carService.addGoodsIntoCar(goodsDto, userId);
    }

    @DeleteMapping("/car/{userId}/goods/{commodityId}")
    public void removeGoodsFromCar(@PathVariable("commodityId")String commodityId,
                                   @PathVariable("userId")String userId){
        carService.removeGoodsFromCar(commodityId,userId );
    }

    @PutMapping("/car/{userId}/goods/{commodityId}/quantity/{quantity}")
    public void updateGoodsInCar(@PathVariable("commodityId")String commodityId,
                                 @PathVariable("userId")String userId,
                                 @PathVariable("quantity")Long quantity) {
        carService.updateGoodsQuantity(commodityId,userId ,quantity );
    }

    @PutMapping("/car/{userId}/goods/{commodityId}/selected")
    public void updateGoodsSelectedInCar(@PathVariable("commodityId")String commodityId,
                                 @PathVariable("userId")String userId,
                                 @RequestParam("selected") Boolean selected) {
        carService.updateGoodsSelected(commodityId, userId, selected);
    }
}
